package com.huixuebao.after.controller.webAuth;


import com.huixuebao.after.dto.RoleFunctionDTO;
import com.huixuebao.after.dto.RoleIdDTO;
import com.huixuebao.after.service.FunctionService;
import com.huixuebao.after.service.RoleService;
import com.huixuebao.common.bean.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/hxb/after/role")
public class WebRoleController {

    @Autowired
    private FunctionService functionService;

    @Autowired
    private RoleService roleService;

    /**
     * 添加角色菜单权限
     * @return
     */
    @PostMapping("/addRoleFunction")
    public ApiResult addRoleFunction(@RequestBody RoleFunctionDTO roleFunctionDTO,HttpServletRequest request){
        /**
         * param = {
         *     "roleName":"",
         *     "perStr":"",
         *     "showSort"",
         *     "status":"",
         *     "remark":"",
         *     "funcIds": "1,2,3"
         * }
         */
        return roleService.addRoleFunction(roleFunctionDTO,request);
    }

    /**
     * 删除角色，以及角色菜单
     */
    @PostMapping("/deleteRoleFunction")
    public ApiResult deleteRoleFunction(@RequestBody RoleIdDTO id){
        return roleService.deleteRoleFunction(id);
    }

    /**
     * 编辑角色管理、角色信息、菜单，
     * @param roleFunction
     * @return
     */
    @PostMapping("/editRoleFunction")
    public ApiResult editRoleFunction(@RequestBody RoleFunctionDTO roleFunction){
        return roleService.editRoleFunction(roleFunction);
    }

    /**
     * 获取角色名称
     */
    @GetMapping("/getRoleName")
    public ApiResult getRoleName(){
        return roleService.getRoleName();
    }

    /**
     * 获取角色列表
     * @return
     */
    @GetMapping("/getRoleList")
    public ApiResult getRoleList(Integer current, Integer size, String roleName, Integer roleState, HttpServletRequest request){
        return roleService.getRoleList(current,size,roleName,roleState,request);
    }
}
